


//获取应用实例
const app = getApp()

Page({
  data: {
    winHeight: wx.getSystemInfoSync().windowHeight + 30,
    bg:null,
    activityid:null
  },
  onLoad: function (res) {
    var that = this;
    this.setData({
      activityid: res.activityid,
    });
    this.getImage();

  },
  //转发按钮触发事件
  onShareAppMessage: function (res) {

    var that = this;
    if (res.from === 'button') {
      // 来自页面内转发按钮
      //console.log(res.target)
      //获取活动的id
      //var activityId = res.target.dataset.activityid;
    }
    return {
      title: '说口令领红包',
      path: '/pages/bonus_detail/bonus_detail?activityid=' + that.data.activityid,
      success: function (res) {
        console.log("转发成功");
      },
      fail: function (res) {
        console.log("转发失败");
      }
    }
  },
  //显示朋友圈图片
  preViewImage: function(e){
    var array = new Array();
    array[0] = this.data.bg;
    wx.previewImage({ // 当前显示图片的http链接  
      current: array[0], // 当前显示图片的http链接 
      urls: array // 需要预览的图片http链接列表  
    })  
  },
  getImage: function(){
    //请求接口获取生成的图片
    var that = this;
    var url = app.data.url + "showImage.do?userId=" + app.data.userid + "&activityId=" + that.data.activityid;
    console.log(url);
    app.sendPost(url,{},function(res){
      console.log("图片地址");
      console.log(res);
      
      if(res.result == "100"){
        that.setData({
          bg: res.data + "?a=" + Math.random() / 9999
        });
      }
      
    });
    
  }
  

})
